package com.zj.service;

import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class UserService implements IuserService{
    public UserService(){
        System.out.println("UserService create");
    }
    private Random random = new Random();
    //增加增删查改方法，输出增删查改

    private void waitsomeTime() {
        try {
            Thread.sleep(random.nextInt(100)+100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public int add(int a,int b) {

        System.out.println("add");
        int c=1/0;
        return a+b;
    }
    public int deleteUser(Integer id) {
        waitsomeTime();
        System.out.println("delete");
        return 1;
    }
    public int updateUser(User user) {
        waitsomeTime();
        System.out.println("update");
        return 1;
    }
    public User selectUser(Integer id) {
        waitsomeTime();

        System.out.println("select");
//        int a=1/0;
        return new User("zhangsan",id,"女");
    }


    public int addUser(User user) {
        waitsomeTime();
//        ((Iuser2DBService) AopContext.currentProxy()).addUser2DB(user);
        System.out.println("addUser");
        return 1;
    }







    public void ping(){
        System.out.println("ping");
    }
}
